package day1106.Company;

import java.util.*;

//1:公司有公司名称，注册地址，电话，经营范围等属性

public class Company implements Comparable<Staff>{
    String name = "aaa";
    String address = "bbb";
    String phonenum = "ccc";
    String industry = "ddd";
    int pos = 0;
    List<Staff> list = new ArrayList<>();
    @Override
    public String toString() {
        return "Company{" +
                "公司名为：'" + name + '\'' +
                ", 公司地址为：'" + address + '\'' +
                ",联系电话为：'" + phonenum + '\'' +
                ",经营范围为：'" + industry + '\'' +
                '}';
    }
    //公司有招聘员工（要求工号不能重复），有输出员工信息，以及辞退员工，和统计公司人数,获得公司薪水最高的员工的方法
    //添加员工
    public void add(String name, int age, String sex, String post, double salary, String num){
        for (int i = 0 ;i<list.size();i++){
            if (list.get(i).getNum().equals(num)){
                System.out.println("工号重复，添加失败");
                return;
            }
        }
        list.add(new Staff(name,age,sex,post,salary,num));
        System.out.println("添加成功");
        pos++;
    }
    //公司人数
    public void num(){
        System.out.println(pos);
    }

    //查询
    public void show(){
        for (int i = 0 ;i<list.size();i++){
            System.out.println(list.get(i));
        }
    }
    //辞退员工
    public void delete(String num){
        for (int i =0;i<list.size();i++){
            if (list.get(i).getNum().equals(num)){
                list.remove(i);
                System.out.println("删除成功");
                return;
            }
        }
        System.out.println("删除失败，工号输入错误");
        return;

    }
    //薪水最高的
    public void max(){
        Staff staff = list.get(0);
        for (int i = 0;i<list.size()-1;i++){
            if (list.get(i).getSalary()>staff.getSalary()){
                staff=list.get(i);
            }
        }
        System.out.println(staff);

    }



    public void raise(String num){
        for (Staff s:list) {
            if (s.getNum().equals(num)){
                if (compareTo(s) == 1){
                    s.setSalary(s.getSalary()+1000);
                    return;
                }
            }
        }
        System.out.println("输入的工号错误或不是年龄最大的");

    }
    @Override
    public int compareTo(Staff o) {
        Staff staff = list.get(0);
        for (int i=0;i<list.size();i++){
            if (staff.getAge()<list.get(i).getAge()){
                staff = list.get(i);
            }
        }
        if (o.getAge()<staff.getAge()){
            return -1;
        }
        return 1;
    }
}
